package com.sxm.yiwei.pinche;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.adapters.pinche.MyPagerAdapter;
import com.sxm.yiwei.base.BaseActivity;
import com.sxm.yiwei.base.BaseFragment;
import com.sxm.yiwei.beans.pinche.Order;
import com.sxm.yiwei.constant.Constant;

import java.util.ArrayList;


public class HostOrdersActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout rl_back;
    private TextView tv_title;
    private ImageView iv_search;
    private ImageView iv_home;
    private TabLayout mTabLayout;
    private String[] tabs={"大巴","私家车"};
    private Order order;
    private int type=Constant.LONG;
    private int page=1;
    private ProgressDialog progressDialog;
    private ViewPager mViewPager;
    private ArrayList<BaseFragment> mFragment=new ArrayList<>();
    private MyPagerAdapter mAdapter;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_host_orders);
    }


    @Override
    public void initData() {
        order = (Order) getIntent().getSerializableExtra("search_param");
        type=order.getStyle();
        switch (order.getStyle()){
            case Constant.LONG:
                tv_title.setText("我是乘客—长途");
                break;
            case Constant.CITY:
                tv_title.setText("我是乘客—同城");
                break;
            case Constant.TRAVEL:
                tv_title.setText("我是乘客—旅游");
                break;
            case Constant.LONG_HURRY:
                tv_title.setText("我是乘客—长途急件");
                break;
        }

        initTabLayout();
    }

    @Override
    public void initView() {
        rl_back = (RelativeLayout)findViewById(R.id.rl_back);
        tv_title = (TextView)findViewById(R.id.tv_title);
        iv_search = (ImageView)findViewById(R.id.iv_search);
        iv_home = (ImageView)findViewById(R.id.iv_home);
        mTabLayout = (TabLayout)findViewById(R.id.tablayout);
        mViewPager = (ViewPager)findViewById(R.id.viewpager);


    }
    private void initTabLayout(){
        mFragment.clear();
        for (int i = 0; i < 2; i++) {
            HostOrdersFragment fragment = new HostOrdersFragment();
            Bundle bundle = new Bundle();
            if (i==0){
                bundle.putInt("vehicle_type",Constant.BUS);
            }else {
                bundle.putInt("vehicle_type",Constant.PRIVATE_CAR);
            }
            bundle.putSerializable("order",order);
            fragment.setArguments(bundle);
            mFragment.add(fragment);
        }

        mAdapter = new MyPagerAdapter(getSupportFragmentManager(),mFragment,this);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(2);

        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setCurrentItem(0);

        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition());
            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }
            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    @Override
    public void initListener() {
        rl_back.setOnClickListener(this);
        iv_search.setOnClickListener(this);
        iv_home.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.iv_search:
                break;
            case R.id.iv_home:
                break;
        }
    }




}
